/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.io.*;

/**
 * <p>Project: javaseapp - WriterDemo
 * <p>Powered by webrx On 2021-08-12 15:25:23
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 16
 */
public class WriterDemo {
    public static void main(String[] args) {
        //字节流
        try (FileOutputStream fos = new FileOutputStream("java3.txt", true)) {
            fos.write("Hello Java 世界！".getBytes());
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        //字符流写入文件 Writer FileWriter BufferedWriter
        try (
                FileWriter fw = new FileWriter("java.txt", true);
                BufferedWriter bufw = new BufferedWriter(new FileWriter("java2.txt"))
        ) {
            fw.write(97);
            fw.append('a');
            fw.append("\r\nhello 世界");
            fw.write("\r\njava2022教程");

            bufw.write("hello\r\njava中文");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
